import Http from '@/api/http'

const user = {
  state: {
    userId:"",
    userName:"",
    token:"",
    permissions: []
  },
  mutations: {
    SET_BTN_PERMISSIONS: (state, permissions) => {
      state.permissions = permissions
    },
    SET_USER_INFO: (state, user) => {
      state.userId = user.userId
      state.userName = user.userName
      state.token = user.token
    },
    SET_USER_TOKEN: (state,token)=>{
      state.token=token
    },
    CLEAN_USER_INFO: (state) => {
      state.userId = ""
      state.userName = ""
      state.token = ""
      state.permissions=[]
    }
  },
  actions: {
    // 设置用户按钮权限信息
    setBtnPerms({ commit, state }) {
      Http.getUserBtnPerms({userId:state.userId}).then(res => {
        if (res.code === 0) {
          if(res.data){
            commit('SET_BTN_PERMISSIONS', res.data)
          }
        }
      }).catch(err=>{
        console.log("getUserBtnPermsErr",err);
      })
    }
  }
}

export default user
